package com.zoagroup.funzy.entity;

import java.io.Serializable;

import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.zoagroup.funzy.entity.pk.RankingGroupPK;


/**
 * The persistent class for the ranking_group database table.
 * 
 */
@Entity
@Table(name="ranking_group")
public class RankingGroup implements Serializable, Comparable<RankingGroup> {
	private static final long serialVersionUID = 1L;

	@EmbeddedId
	private RankingGroupPK id;

	private int score;

	//bi-directional many-to-one association to Group
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="id_group", insertable=false, updatable=false)
	private Group group;

	//bi-directional many-to-one association to Ranking
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="id_ranking", insertable=false, updatable=false)
	private Ranking ranking;

	public RankingGroup() {
	}

	public RankingGroupPK getId() {
		return this.id;
	}

	public void setId(RankingGroupPK id) {
		this.id = id;
	}

	public int getScore() {
		return this.score;
	}

	public void setScore(int score) {
		this.score = score;
	}

	public Group getGroup() {
		return this.group;
	}

	public void setGroup(Group group) {
		this.group = group;
	}

	public Ranking getRanking() {
		return this.ranking;
	}

	public void setRanking(Ranking ranking) {
		this.ranking = ranking;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		RankingGroup other = (RankingGroup) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	@Override
	public int compareTo(RankingGroup obj) {
		if (this == obj)
			return 0;
		if (obj == null)
			return 1;
		if (getClass() != obj.getClass())
			return 1;
		RankingGroup other = (RankingGroup) obj;
		
		if(other.getScore() < this.getScore()){
			return -1;
		} else if(other.getScore() == this.getScore()) {
			return 0;
		} else {
			return -1;
		}
	}
}